<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.serviceno" placeholder="业务件号" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-input v-model="dataForm.realtyno" placeholder="登记证明号" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-input v-model="dataForm.obankid" placeholder="银行编号" clearable></el-input>
      </el-form-item>

      <el-form-item>
        <el-input v-model="dataForm.region" placeholder="区域代码" clearable></el-input>
      </el-form-item>

       <el-form-item>
        <el-date-picker
          v-model="dataForm.begindate"
          type="datetime"
          placeholder="选择起始时间"
          align="right"
          default-time="00:00:00"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>   

      <el-form-item>
        <el-date-picker
          v-model="dataForm.enddate"
          type="datetime"
          placeholder="选择结束时间"
          default-time="23:59:59"
          align="right"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item> 

      <!-- <el-form-item label="地市" prop="seRegion">
        <el-select  @change="selectChanged" v-model="dataForm.seRegion" placeholder="区域" style="width:100%">
            <el-option
              v-for="item in dataForm.seRegionList"
              :key="item.code"
              :label="item.name"
              :value="item.code">
            </el-option>
        </el-select>
     </el-form-item>

    <el-form-item label="区县" prop="region">
      <el-select v-model="dataForm.region" placeholder="区县" style="width:100%">
          <el-option
            v-for="item in dataForm.regionList"
            :key="item.code"
            :label="item.name"
            :value="item.code">
          </el-option>
      </el-select>
    </el-form-item> -->

      <el-form-item>
        <el-button  type="primary" @click="getDataList()">本地查询</el-button>
        <el-button type="primary" @click="export2Excel('table')">导出</el-button> 
        <el-button v-if="isAuth('bdc:bdccertinfo:save')" type="primary" @click="addOrUpdateHandle()">新增查询信息</el-button>
      </el-form-item>
    </el-form>

    <el-table
      :data="dataList"
      border
      id="table"
      style="width: 100%;display:none;">

      <el-table-column
        prop="dealtime"
        header-align="center"
        align="center"
          width="160px"
        label="查询时间">
      </el-table-column>

      <el-table-column
        prop="obankid"
        header-align="center"
        width="120px"
        align="center"
        label="发起行">
      </el-table-column>

      <el-table-column
        prop="region"
        header-align="center"
        align="center"
        label="区域代码">
      </el-table-column>

      <el-table-column
        prop="djjg"
        header-align="center"
        width="170px"
        align="center"
        label="登记机构">
      </el-table-column>

      <el-table-column
        prop="serviceno"
        header-align="center"
        width="170px"
        align="center"
        label="业务件号">
      </el-table-column>
      <el-table-column
        prop="realtyno"
        header-align="center"
        width="300px"
        align="center"
        label="不动产登记证明号">
      </el-table-column>
      <el-table-column
        prop="servicecode"
        header-align="center"
        width="170px"
        align="center"
        label="业务标识码">
      </el-table-column>

      <el-table-column
        prop="qlrmc"
        header-align="center"
        align="center"
        label="权利人">
      </el-table-column>
      <el-table-column
        prop="ywrmc"
        header-align="center"
        align="center"
         width="160px"
        label="义务人名称">
      </el-table-column>
      <el-table-column
        prop="zl"
        header-align="center"
        align="center"
         width="300px"
        label="房屋坐落">
      </el-table-column>
      <el-table-column
        prop="realtyunitno"
        header-align="center"
         width="160px"
        align="center"
        label="不动产单元号">
      </el-table-column>
    </el-table>

    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">

      <el-table-column
        prop="dealtime"
        header-align="center"
        align="center"
          width="160px"
        label="查询时间">
      </el-table-column>

      <el-table-column
        prop="obankid"
        header-align="center"
        width="120px"
        align="center"
        label="发起行">
      </el-table-column>

      <el-table-column
        prop="region"
        header-align="center"
        align="center"
        label="区域代码">
      </el-table-column>

      <el-table-column
        prop="djjg"
        header-align="center"
        width="170px"
        align="center"
        label="登记机构">
      </el-table-column>

      <el-table-column
        prop="serviceno"
        header-align="center"
        width="170px"
        align="center"
        label="业务件号">
      </el-table-column>
      <el-table-column
        prop="realtyno"
        header-align="center"
        width="300px"
        align="center"
        label="不动产登记证明号">
      </el-table-column>
      <el-table-column
        prop="servicecode"
        header-align="center"
        width="170px"
        align="center"
        label="业务标识码">
      </el-table-column>

      <el-table-column
        prop="qlrmc"
        header-align="center"
        align="center"
        label="权利人">
      </el-table-column>
      <el-table-column
        prop="ywrmc"
        header-align="center"
        align="center"
         width="160px"
        label="义务人名称">
      </el-table-column>
      <el-table-column
        prop="zl"
        header-align="center"
        align="center"
         width="300px"
        label="房屋坐落">
      </el-table-column>
      <el-table-column
        prop="realtyunitno"
        header-align="center"
         width="160px"
        align="center"
        label="不动产单元号">
      </el-table-column>





      <el-table-column
        fixed="left"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="searchHandle(scope.row.serialno)">查询证明信息</el-button>
          <el-button type="text" size="mini" @click="detailHandle(scope.row.serialno)">详情</el-button>
          <el-button type="text" size="mini" @click="downFileHandle(scope.row.serialno)" v-if="scope.row.fname">
            下载电子证明</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="datepicker.pageOptions"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <bdccertinfo-detail v-if="bdccertinfoDetailVisible" ref="bdccertinfoDetail" ></bdccertinfo-detail>
  </div>
</template>

<script>
  import AddOrUpdate from './bdccertinfo-add-or-update'
  import BdccertinfoDetail from './bdccertinfo-detail'
  export default {
    data () {
      return {
        pickerOptions: this.datepicker.pickerOptions,
        dataForm: {
          serviceno: '',
          realtyno: '',
          obankid: '',
          region: '',
            begindate: '',
            enddate: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        bdccertinfoDetailVisible: false
      }
    },
    components: {
      AddOrUpdate,
      BdccertinfoDetail
    },
    activated () {
      this.getDataList()
    },
    methods: {
      export2Excel(id){
          this.datepicker.export2Excel(id, this, '电子证明查询.xlsx')
      },

      downFileHandle(id){
          var token = this.$cookie.get('token')
      　　var url = this.$http.adornUrl('/bdc/bdccertinfo/down/' + id + '?token=' + token)
          window.location.href = url
      },

      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bdc/bdccertinfo/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'serviceno': this.dataForm.serviceno,
            'realtyno': this.dataForm.realtyno,
            'obankid': this.dataForm.obankid,
            'enddate': this.dataForm.enddate,
            'begindate': this.dataForm.begindate,
            'region': this.dataForm.region
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      detailHandle (id) {
        this.bdccertinfoDetailVisible = true
        this.$nextTick(() => {
          this.$refs.bdccertinfoDetail.init(id)
        })
      },
      searchHandle(id){
        this.$http({
              url: this.$http.adornUrl(`/bdc/bdccertinfo/search`),
              method: 'post',
              data: this.$http.adornData({

                'serialno': id


              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500
                })
              } else {
                this.$message.error(data.msg)
              }
            })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.serialno
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/bdc/bdccertinfo/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style lang="scss">
body .el-table th.gutter{
    display: table-cell!important;

}

</style>